<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="查看性能工具系统ps | grep 查进程idless awktop JVM系列工具jstat:查看内存分配，gc情况jstack:查看进程的线程栈jmap:dump java内存（不要对在线的进程使用） 应用工具mat:分析内存问题监控工具:zabbix 进程耗CPU案例死循环:jstack查看一下线程id是否一致在runnable，多打印几次就能发现 进程耗cpu过高1.ps aux | gr">
<meta property="og:type" content="article">
<meta property="og:title" content="排查问题笔录">
<meta property="og:url" content="http://yoursite.com/2017/12/07/gc/问题排查经验/index.html">
<meta property="og:site_name" content="Tissan">
<meta property="og:description" content="查看性能工具系统ps | grep 查进程idless awktop JVM系列工具jstat:查看内存分配，gc情况jstack:查看进程的线程栈jmap:dump java内存（不要对在线的进程使用） 应用工具mat:分析内存问题监控工具:zabbix 进程耗CPU案例死循环:jstack查看一下线程id是否一致在runnable，多打印几次就能发现 进程耗cpu过高1.ps aux | gr">
<meta property="og:updated_time" content="2017-12-18T05:11:02.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="排查问题笔录">
<meta name="twitter:description" content="查看性能工具系统ps | grep 查进程idless awktop JVM系列工具jstat:查看内存分配，gc情况jstack:查看进程的线程栈jmap:dump java内存（不要对在线的进程使用） 应用工具mat:分析内存问题监控工具:zabbix 进程耗CPU案例死循环:jstack查看一下线程id是否一致在runnable，多打印几次就能发现 进程耗cpu过高1.ps aux | gr">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 'undefined',
      author: 'Java程序员'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/12/07/gc/问题排查经验/"/>





  <title>排查问题笔录 | Tissan</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Tissan</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/12/07/gc/问题排查经验/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="罗天翔">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tissan">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">排查问题笔录</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-07T21:12:09+08:00">
                2017-12-07
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/JVM/" itemprop="url" rel="index">
                    <span itemprop="name">JVM</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/2017/12/07/gc/问题排查经验/#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2017/12/07/gc/问题排查经验/" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="查看性能工具"><a href="#查看性能工具" class="headerlink" title="查看性能工具"></a>查看性能工具</h3><h4 id="系统"><a href="#系统" class="headerlink" title="系统"></a>系统</h4><p>ps | grep 查进程id<br>less awk<br>top</p>
<h4 id="JVM系列工具"><a href="#JVM系列工具" class="headerlink" title="JVM系列工具"></a>JVM系列工具</h4><p>jstat:查看内存分配，gc情况<br>jstack:查看进程的线程栈<br>jmap:dump java内存（不要对在线的进程使用）</p>
<h4 id="应用工具"><a href="#应用工具" class="headerlink" title="应用工具"></a>应用工具</h4><p>mat:分析内存问题<br>监控工具:zabbix</p>
<h3 id="进程耗CPU"><a href="#进程耗CPU" class="headerlink" title="进程耗CPU"></a>进程耗CPU</h3><p><code>案例</code><br>死循环:jstack查看一下线程id是否一致在runnable，多打印几次就能发现</p>
<h4 id="进程耗cpu过高"><a href="#进程耗cpu过高" class="headerlink" title="进程耗cpu过高"></a>进程耗cpu过高</h4><p>1.ps aux | grep #pid#<br>2.top -H -p #pid#<br>3.找到耗cpu高的线程id<br>4.print %x tid 把线程转化成16进制<br>5.jstack -l #pid# dump出线程栈<br>6.在线程栈中找到tid的相应的线程</p>
<h4 id="gc线程消耗cpu时间"><a href="#gc线程消耗cpu时间" class="headerlink" title="gc线程消耗cpu时间"></a>gc线程消耗cpu时间</h4><p>1.fullGC多<br>2.频繁YGC</p>
<blockquote>
<p>需要配置的参数:-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -Xloggc:/data/log/gc/gc.log<br>如果没有配置就使用 jstat -gc pid 1000 观察ygc和fullGC的次数时间等</p>
</blockquote>
<h3 id="线程hang住"><a href="#线程hang住" class="headerlink" title="线程hang住"></a>线程hang住</h3><p>1.本地锁,分布式锁<br>2.线程耗尽,连接池耗尽<br>3.死循环<br>4.带宽耗尽<br>5.远程服务没有设置超时时间<br>6.周期性fullGC</p>
<h3 id="进程OOM"><a href="#进程OOM" class="headerlink" title="进程OOM"></a>进程OOM</h3><h4 id="类型"><a href="#类型" class="headerlink" title="类型"></a>类型</h4><p><code>gc overhead limit exceeded</code><br>jvm花大量时间回收少量内存<br><code>java heap space</code><br>heap大小:-Xms -Xmx<br><code>unable to create native thread</code><br>线程超过系统:是不是哪里用了new Thread而不是线程池<br><code>Perm Gen Space</code><br>持久代不够用,调大PermSize参数<br>ClassLoader错误<br><code>direct buffer memory</code><br>direct buffer 使用超出限制的大小，默认为-Xmx<br>使用堆外内存,一般是网络通信没有限流，而且用内存做buffer<br><code>map failed</code><br>File Channel map的文件超过限制</p>
<h4 id="怎么解决"><a href="#怎么解决" class="headerlink" title="怎么解决"></a>怎么解决</h4><p>jmap -dump:format=b,file=heap.hprof dump #pid#(如果没有crash)<br>使用mat分析<br>可以看出内存使用,来检验ygc和fullGC根源</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/uploads/wechat.png" alt="罗天翔 WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="/uploads/ali.jpg" alt="罗天翔 Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/12/01/pattern/原型模式/" rel="next" title="原型模式">
                <i class="fa fa-chevron-left"></i> 原型模式
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/12/09/pattern/单例模式/" rel="prev" title="单例模式">
                单例模式 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="SOHUCS"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/avatar.jpg"
               alt="罗天翔" />
          <p class="site-author-name" itemprop="name">罗天翔</p>
           
              <p class="site-description motion-element" itemprop="description">一次就把事情做对.</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/louiegit/" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="" target="_blank" title="微信">
                  
                    <i class="fa fa-fw fa-wechat"></i>
                  
                  微信
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#查看性能工具"><span class="nav-number">1.</span> <span class="nav-text">查看性能工具</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#系统"><span class="nav-number">1.1.</span> <span class="nav-text">系统</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JVM系列工具"><span class="nav-number">1.2.</span> <span class="nav-text">JVM系列工具</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#应用工具"><span class="nav-number">1.3.</span> <span class="nav-text">应用工具</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#进程耗CPU"><span class="nav-number">2.</span> <span class="nav-text">进程耗CPU</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#进程耗cpu过高"><span class="nav-number">2.1.</span> <span class="nav-text">进程耗cpu过高</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#gc线程消耗cpu时间"><span class="nav-number">2.2.</span> <span class="nav-text">gc线程消耗cpu时间</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#线程hang住"><span class="nav-number">3.</span> <span class="nav-text">线程hang住</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#进程OOM"><span class="nav-number">4.</span> <span class="nav-text">进程OOM</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#类型"><span class="nav-number">4.1.</span> <span class="nav-text">类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#怎么解决"><span class="nav-number">4.2.</span> <span class="nav-text">怎么解决</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">罗天翔</span>
</div>


<div class="powered-by">
  NBA & Code. What?
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cyt9ceIwz';
      var conf = 'c6226e2bfb7e9c65efc235736edc5074';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  




  





  

  

  

  

  

  

</body>
</html>
